﻿using AnQinFrameWorkAPI.Entity.Blog.DTO.BlogGlobalConfig;
using AnQinFrameWorkAPI.Entity.Blog.View.BlogGlobalConfig;
using AnQinFrameWorkAPI.Service.Blog;
using FrameWork.Entity;
using Microsoft.AspNetCore.Mvc;

namespace AnQinFrameWorkAPI.Controllers.Blog;

/// <summary>
///     博客全局配置API
/// </summary>
[Route("api/[controller]")]
[ApiController]
[ApiExplorerSettings(GroupName = "Blog")]
public class BlogGlobalConfigController : ControllerBase
{
    // 业务服务接口
    private readonly BlogGlobalConfigService _blogGlobalConfigService;

    // 构造注入
    public BlogGlobalConfigController(BlogGlobalConfigService blogGlobalConfigService)
    {
        _blogGlobalConfigService = blogGlobalConfigService;
    }

    /// <summary>
    ///     获取全局配置列表
    /// </summary>
    /// <param name="searchDTO">查询条件</param>
    [ProducesResponseType(typeof(BlogGlobalConfigView), 200)]
    [HttpGet]
    public async Task<IActionResult> GetBlogGlobalConfigList([FromQuery] BlogGlobalConfigSearchDTO searchDTO)
    {
        var response = await _blogGlobalConfigService.GetBlogGlobalConfigList(searchDTO);
        return StatusCode(response.Status, response);
    }

    /// <summary>
    ///     新增全局配置
    /// </summary>
    /// <param name="addDTO">配置数据</param>
    [HttpPost]
    public async Task<IActionResult> AddBlogGlobalConfig([FromBody] BlogGlobalConfigAddDTO addDTO)
    {
        var response = await _blogGlobalConfigService.AddBlogGlobalConfig(addDTO);
        return StatusCode(response.Status, response);
    }

    /// <summary>
    ///     更新全局配置
    /// </summary>
    /// <param name="updateDTO">配置数据</param>
    [HttpPut]
    public async Task<IActionResult> PutBlogGlobalConfig([FromBody] BlogGlobalConfigUpdateDTO updateDTO)
    {
        var response = await _blogGlobalConfigService.PutBlogGlobalConfig(updateDTO);
        return StatusCode(response.Status, response);
    }

    /// <summary>
    ///     删除全局配置
    /// </summary>
    /// <param name="deleteDTO">删除参数</param>
    [HttpDelete]
    public async Task<IActionResult> DeleteBlogGlobalConfig([FromBody] SingleIdDTO deleteDTO)
    {
        var response = await _blogGlobalConfigService.DeleteBlogGlobalConfig(deleteDTO);
        return StatusCode(response.Status, response);
    }
}